home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / docme.lha / doc.me / multiple.me < prev    next >
Text File  |  1992-09-25  |  44KB  |  1,395 lines

  1. .\" use: pic | tbl | eqn | ditroff -me
  2. .\"
  3. .\"    "@(#)bibmac.me    2.2    9/9/83";
  4. .de IP
  5. .ip \\$1 \\$2
  6. ..
  7. .de LP
  8. .lp
  9. ..
  10. .\"    @(#)bmac.std    2.2    9/9/83;
  11. .\" standard format troff commands
  12. .\" citation formatting strings
  13. .ds [[ [
  14. .ds ]] ]
  15. .ds ], ,\|
  16. .ds ]- -
  17. .ds [. " \&
  18. .ds .] .
  19. .ds [, " \&
  20. .ds ,] ,
  21. .ds [? " \&
  22. .ds ?] ?
  23. .ds [: " \&
  24. .ds :] :
  25. .ds [; " \&
  26. .ds ;] ;
  27. .ds [! " \&
  28. .ds !] !
  29. .ds [" " \&
  30. .ds "] \&"
  31. .ds [' " \&
  32. .ds '] '
  33. .ds [< " \&
  34. .ds >]
  35. .\" reference formmating strings
  36. .ds a] " \&
  37. .ds b] , \&
  38. .ds c] , \&
  39. .ds n] "\& and \&
  40. .ds m] "\& and \&
  41. .ds p] .
  42. .\" reference formmating macros
  43. .de s[   \" start reference
  44. .nh
  45. .IP [\\*([F] 5m
  46. ..
  47. .de e[   \" end reference
  48. .[-
  49. ..
  50. .de []   \" start to display collected references
  51. .LP
  52. ..
  53. .de ][   \" choose format
  54. .ie !"\\*([J"" \{\
  55. .    ie !"\\*([V"" .nr t[ 1    \" journal
  56. .    el            .nr t[ 5    \" conference paper
  57. .\}
  58. .el .ie !"\\*([B"" .nr t[ 3    \" article in book
  59. .el .ie !"\\*([R"" .nr t[ 4    \" technical report
  60. .el .ie !"\\*([I"" .nr t[ 2    \" book
  61. .el                .nr t[ 0    \" other
  62. .\\n(t[[
  63. ..
  64. .de 0[   \" other
  65. .s[
  66. .if !"\\*([A"" \\*([A\\c
  67. .if !"\\*([T"" , \\*([T\\c
  68. .if !"\\*([V"" , Vol. \\*([V\\c
  69. .if !"\\*([O"" , \\*([O\\c
  70. .if !"\\*([D"" , \\*([D\\c
  71. \&.
  72. .e[
  73. ..
  74. .de 1[ \" journal article
  75. .s[
  76. .if !"\\*([A"" \\*([A,
  77. .if !"\\*([T""  \\*([T,
  78. \\fI\\*([J \\*([V\\fP\c
  79. .if !"\\*([N"" ,\\*([N
  80. .if !"\\*([D"" (\\*([D)\c
  81. .if !"\\*([P"" , \\*([P\c
  82. .if !"\\*([I"" , \\*([I\c
  83. \\&.
  84. .if !"\\*([O"" \\*([O.
  85. .e[
  86. ..
  87. .de 2[ \" book
  88. .s[
  89. .ie !"\\*([A"" \\*([A,
  90. .el .if !"\\*([E"" \{\
  91. .       ie \\n([E-1 \\*([E, eds.,
  92. .       el \\*([E, ed.,\}
  93. .if !"\\*([T"" \\fI\\*([T\\fP,
  94. .rm a[
  95. .if !"\\*([I"" .ds a[ \\*([I
  96. .if !"\\*([C"" \{\
  97. .       if !"\\*(a["" .as a[ , \\&
  98. .       as a[ \\*([C\}
  99. .if !"\\*([D"" \{\
  100. .       if !"\\*(a["" .as a[ , \\&
  101. .       as a[ \\*([D\}
  102. \\*(a[.
  103. .if !"\\*([G"" Gov. ordering no. \\*([G.
  104. .if !"\\*([O"" \\*([O.
  105. .e[
  106. ..
  107. .de 3[ \" article in book
  108. .s[
  109. .if !"\\*([A"" \\*([A,
  110. .if !"\\*([T"" \\*([T,
  111. in \\fI\\*([B\\fP\c
  112. .if !"\\*([V"" , vol. \\*([V
  113. .if !~\\*([E~~ \{\
  114. .       ie , \\n([E-1  \\*([E (editors)\c
  115. .       el , \\*([E (editor)\c\}
  116. .if !"\\*([I"" , \\*([I\c
  117. .if !"\\*([C"" , \\*([C\c
  118. .if !"\\*([D"" , \\*([D\c
  119. .if !"\\*([P"" , \\*([P\c
  120. \\&.
  121. .if !"\\*([O"" \\*([O.
  122. .e[
  123. ..
  124. .de 4[ \" report
  125. .s[
  126. .if !"\\*([A"" \\*([A,
  127. .if !~\\*([E~~ \{\
  128. .       ie \\n([E-1 \\*([E, editors.
  129. .       el \\*([E, editor.\}
  130. \\*([T,
  131. \\*([R\c
  132. .if !"\\*([G"" \& (\\*([G)\c
  133. .if !"\\*([I"" , \\*([I\c
  134. .if !"\\*([C"" , \\*([C\c
  135. .if !"\\*([D"" , \\*([D\c
  136. \\&.
  137. .if !"\\*([O"" \\*([O.
  138. .e[
  139. ..
  140. .de 5[ \" conference paper
  141. .s[
  142. .if !"\\*([A"" \\*([A,
  143. .if !"\\*([T"" \\*([T,
  144. \\fI\\*([J\\fP,
  145. .if !"\\*([C"" \\*([C,
  146. .if !"\\*([D"" \\*([D\c
  147. .if !"\\*([P"" , \\*([P\c
  148. \\&.
  149. .if !"\\*([O"" \\*([O.
  150. .e[
  151. ..
  152. .de [-   \" clean up after yourself
  153. .rm [A [B [C [D
  154. .rm [E [F [G
  155. .rm [I [J [K
  156. .rm [N [O [P
  157. .rm [R [T
  158. .rm [V [W
  159. ..
  160. .\"    @(#)bmac.std    2.2    8/24/83;
  161. .\" standard format troff commands
  162. .\" citation formatting strings
  163. .ds [[ [
  164. .ds ]] ]
  165. .ds ], ,\|
  166. .ds ]- -
  167. .ds [. " \&
  168. .ds .] .
  169. .ds [, " \&
  170. .ds ,] ,
  171. .ds [< " \&
  172. .ds >]
  173. .\" reference formmating strings
  174. .ds c] , \&
  175. .ds n] "" and \&
  176. .ds m] "" and \&
  177. .ds a] " \&
  178. .\" reference formmating macros
  179. .de s[   \" start reference
  180. .nh
  181. .IP [\\*([F] 5m
  182. ..
  183. .de e[   \" end reference
  184. .[-
  185. ..
  186. .de []   \" start to display collected references
  187. .SH
  188. References
  189. .LP
  190. ..
  191. .de ][   \" choose format
  192. .ie !"\\*([J"" \{\
  193. .    ie !"\\*([V"" .nr t[ 1    \" journal
  194. .    el            .nr t[ 5    \" conference paper
  195. .\}
  196. .el .ie !"\\*([B"" .nr t[ 3    \" article in book
  197. .el .ie !"\\*([R"" .nr t[ 4    \" technical report
  198. .el .ie !"\\*([I"" .nr t[ 2    \" book
  199. .el                .nr t[ 0    \" other
  200. .\\n(t[[
  201. ..
  202. .de 0[   \" other
  203. .s[
  204. .if !"\\*([A"" \\*([A,
  205. .if !"\\*([T"" \\*([T,
  206. .if !"\\*([O"" \\*([O\c
  207. .if !"\\*([D"" , \\*([D\c
  208. \&.
  209. .e[
  210. ..
  211. .de 1[ \" journal article
  212. .s[
  213. .if !"\\*([A"" \\*([A,
  214. .if !"\\*([T"" \\*([T,
  215. \\fI\\*([J \\*([V\\fP,
  216. .if !"\\*([N"" \\*([N
  217. .if !"\\*([D"" (\\*([D),
  218. .if !"\\*([P"" \\*([P\c
  219. .if !"\\*([I"" , \\*([I\c
  220. \\&.
  221. .if !"\\*([O"" \\*([O.
  222. .e[
  223. ..
  224. .de 2[ \" book
  225. .s[
  226. .ie !"\\*([A"" \\*([A,
  227. .el .if !"\\*([E"" \{\
  228. .       ie \\n([E-1 \\*([E, eds.,
  229. .       el \\*([E, ed.,\}
  230. .if !"\\*([T"" \\fI\\*([T\\fP,
  231. .rm a[
  232. .if !"\\*([I"" .ds a[ \\*([I
  233. .if !"\\*([C"" \{\
  234. .       if !"\\*(a["" .as a[ , \\&
  235. .       as a[ \\*([C\}
  236. .if !"\\*([D"" \{\
  237. .       if !"\\*(a["" .as a[ , \\&
  238. .       as a[ \\*([D\}
  239. \\*(a[.
  240. .if !"\\*([G"" Gov. ordering no. \\*([G.
  241. .if !"\\*([O"" \\*([O.
  242. .e[
  243. ..
  244. .de 3[ \" article in book
  245. .s[
  246. .if !"\\*([A"" \\*([A,
  247. .if !"\\*([T"" \\*([T,
  248. in \\fI\\*([B\\fP,
  249. .if !"\\*([V"" vol. \\*([V,
  250. .if !"\\*([E"" \\*([E (ed.),
  251. .if !"\\*([I"" \\*([I,
  252. .if !"\\*([C"" \\*([C,
  253. .if !"\\*([D"" \\*([D\c
  254. .if !"\\*([P"" , \\*([P\c
  255. \\&.
  256. .if !"\\*([O"" \\*([O.
  257. .e[
  258. ..
  259. .de 4[ \" report
  260. .s[
  261. .if !"\\*([A"" \\*([A,
  262. \\*([T,
  263. \\*([R\c
  264. .if !"\\*([G"" \& (\\*([G)\c
  265. .if !"\\*([I"" , \\*([I\c
  266. .if !"\\*([C"" , \\*([C\c
  267. .if !"\\*([D"" , \\*([D\c
  268. \\&.
  269. .if !"\\*([O"" , \\*([O.
  270. .e[
  271. ..
  272. .de 5[ \" conference paper
  273. .s[
  274. .if !"\\*([A"" \\*([A,
  275. .if !"\\*([T"" \\*([T,
  276. \\fI\\*([J\\fP,
  277. .if !"\\*([C"" \\*([C\c
  278. .if !"\\*([D"" , \\*([D\c
  279. .if !"\\*([P"" , \\*([P\c
  280. \\&.
  281. .if !"\\*([O"" , \\*([O.
  282. .e[
  283. ..
  284. .de [-   \" clean up after yourself
  285. .rm [A [B [C [D
  286. .rm [E [F [G
  287. .rm [I [J [K
  288. .rm [N [O [P
  289. .rm [R [T
  290. .rm [V [W
  291. ..
  292. .if t \{ \
  293. .pl 29.7c    \" page length
  294. .po 2.5c    \" page offset (left margin)
  295. .ll 16.5c    \" line length
  296. .lt 16.5c    \" title length
  297. .nr LL 16.5c
  298. .nr )l 29.7c
  299. .nr hm 2c
  300. .nr $r 9    \" factor for vertical spacing
  301. .nr $R \n($r
  302. .sz 12        \" font size
  303. .nr pp 12
  304. .nr sp 12
  305. .nr tp 12
  306. .nr fp 10
  307. .hc ~        \" hyphenation character
  308. .        \" Umlauts and sharp s
  309. .ds A \(A:
  310. .ds O \(O:
  311. .ds U \(U:
  312. .ds a \(a:
  313. .ds o \(o:
  314. .ds u \(u:
  315. .ds s \(ss
  316. .        \"  UMLAUT  \*:u, etc.
  317. .ds : \v'-0.6m'\h'(1u-(\\n(.fu%2u))*0.13m+0.06m'\z.\h'0.2m'\z.\h'-((1u-(\\n(.fu%2u))*0.13m+0.26m)'\v'0.6m'
  318. .\}
  319. .if n \{ \
  320. .po 0        \" page offset (left margin)
  321. .ll 78        \" line length
  322. .lt 78        \" title length
  323. .nr $r 4    \" factor for vertical spacing
  324. .nr $R \n($r
  325. .hc ~        \" hyphenation character
  326. .        \" Umlaute und scharfes s
  327. .ds A Ae
  328. .ds O Oe
  329. .ds U Ue
  330. .ds a ae
  331. .ds o oe
  332. .ds u ue
  333. .ds s sz
  334. .\}
  335. .de _
  336. \&\\$1\l'|0\(ul'\\$2
  337. ..
  338. .de FT        \" font for programs
  339. .ft C
  340. .sz -2
  341. ..
  342. .de FR
  343. .ft R
  344. .sz +2
  345. ..
  346. .de []        \" start to display collected references
  347. .uh References
  348. .lp
  349. ..
  350. .de $0        \" collect table of contents
  351. .(x
  352. .ta 2c
  353. .ie '\\$2''    \\$1
  354. .el \\$2.    \\$1
  355. .)x
  356. ..
  357. .de np
  358. .nr $p +1
  359. .ip \\n($p.
  360. ..
  361. .de SH
  362. .sp 0.5
  363. .in -3
  364. .r \\$1
  365. .sp 0.5
  366. .in +3
  367. ..
  368. .de PP
  369. .sp 0.5
  370. ..
  371. .de IP
  372. .ip \\$1 \\$2
  373. ..
  374. .de I
  375. .i \\$1
  376. ..
  377. .de TH
  378. ..
  379. .EQ
  380. gsize 12
  381. gfont R
  382. delim $$
  383. .EN
  384. .hc ~
  385. .ds ], , 
  386. .b " "
  387. .sp 1c
  388. .ta 9c
  389. .ft R
  390. .sz 12
  391. \l'17.1c'
  392. .nf
  393.  
  394.     Multiple Inheritance
  395.     in Object-Oriented
  396.     Attribute Grammars
  397.  
  398.     J. Grosch
  399.  
  400.  
  401. \l'17.1c'
  402. .sp 12.5c
  403. \l'17.1c'
  404. .ft H
  405. .nf
  406.     GESELLSCHAFT F\*UR MATHEMATIK
  407.     UND DATENVERARBEITUNG MBH
  408.  
  409.     FORSCHUNGSSTELLE F\*UR
  410.     PROGRAMMSTRUKTUREN
  411.     AN DER UNIVERSIT\*AT KARLSRUHE
  412. .r
  413. \l'17.1c'
  414. .bp
  415. .\" .oh '''%'
  416. .\" .eh '''%'
  417. .ce 99
  418. .sz 20
  419. .b " "
  420. .sp 2
  421. Project
  422. .sp
  423. .b "Compiler Generation"
  424. .sp
  425. .sz 12
  426. \l'15c'
  427. .sp
  428. .sz 16
  429. .b "Multiple Inheritance in Object-Oriented Attribute Grammars"
  430. .sp 2
  431. Josef Grosch
  432. .sp 2
  433. .sz 14
  434. Feb. 25, 1992
  435. .sp
  436. .sz 12
  437. \l'15c'
  438. .sp 2
  439. Report No. 28
  440. .sp 2
  441. Copyright \(co 1992 GMD
  442. .sp 2
  443. Gesellschaft f\*ur Mathematik und Datenverarbeitung mbH
  444. Forschungsstelle an der Universit\*at Karlsruhe
  445. Vincenz-Prie\*snitz-Str. 1
  446. D-7500 Karlsruhe
  447. .ce 0
  448. .fi
  449. .oh '''%'
  450. .eh '''%'
  451. .bp 1
  452. .ce 99
  453. .b "Multiple Inheritance in Object-Oriented Attribute Grammars"
  454. .sp 2
  455. Josef Grosch
  456. GMD Forschungsstelle an der Universit\*at Karlsruhe
  457. Vincenz-Prie\*snitz-Str. 1, D-7500 Karlsruhe, Germany
  458. grosch@karlsruhe.gmd.de
  459. .ce 0
  460. .sp 2
  461. .uh Abstract
  462. Object-oriented attribute grammars are a promising notation for language specifications.
  463. They have similar benefits as object-orientation in the area of programming languages. They
  464. support a compact and flexible style for language specifications. Existing definitions can
  465. be easily reused as well as the associated default behaviour. New definitions can be
  466. derived from existing ones by specialization. While previous approaches have been
  467. restricted to single inheritance this paper defines object-oriented attribute grammars
  468. with multiple inheritance. A system has been developed that processes those attribute
  469. grammars. We describe an example that uses multiple inheritance and compare the terminology
  470. and concepts of related areas.
  471. .uh Keywords
  472. attribute grammar, object-orientation, multiple inheritance
  473. .sh 1 Introduction
  474. .lp
  475. Object-oriented attribute grammars have been introduced by several authors (e. g.
  476. \*([[Gro90a\*(],Hed89\*(]])
  477. as a promising notation for attribute grammars.
  478. An overview of the current state of the art in this area is given in
  479. \*([[Kos91\*(]].
  480. The benefits are comparable to those of object-oriented programming languages.
  481. It is a concise notation and flexible notation for language specifications.
  482. The reuse of existing definitions is supported by the
  483. possibility to specify new definitions as extensions or specializations of existing ones.
  484. The duplication of information is avoided because common parts can be "factored out".
  485. .pp
  486. While the main building blocks of object-oriented programming languages are classes, the
  487. nonterminals play this part in object-oriented attribute grammars. More precisely, the
  488. notions nonterminal and production rule are unified. This means that there is exactly one
  489. production rule for every nonterminal. Additionally, a relation between nonterminals is
  490. specified, for example using chain rules, which describes a subtype relation or class
  491. hierarchy among the nonterminals. This subtype relation serves for two purposes. First, it
  492. allows to derive several different strings from one nonterminal because a nonterminal may
  493. be replaced by a right-hand side corresponding to a nonterminal that is a subtype of the
  494. replaced one. Second, the subtype relation describes the path for inheritance among the
  495. nonterminals. The items that are subject to inheritance are right-hand side elements,
  496. attributes, and attribute computations.
  497. Inherited attribute computations may be overwritten in the subtype
  498. by giving different computations for the same attributes.
  499. .pp
  500. Before we proceed we have to clarify the terminology:
  501. Originally, context-free grammars as well as attribute grammars are derivation systems for
  502. strings. In this paper we are interested in the specification of semantic analysis which is
  503. based on an abstract syntax tree. Therefore we use grammars to describe the structure of
  504. trees instead of strings.
  505. .lp
  506. In order to avoid confusion between the terms class, nonterminal, terminal, and (sub)type
  507. we will use the term
  508. .i "node type"
  509. to cover all those meanings. The term node type is motivated through a realistic
  510. description of what is happening: The node types specify the structure of the nodes of the
  511. abstract syntax tree.
  512. .lp
  513. The attributes in attribute grammars are usually classified as
  514. .i synthesized
  515. and
  516. .i inherited .
  517. Following Hedin\*([<\*([[Hed89\*(]]\*(>] we use the term
  518. .i "ancestral attribute"
  519. instead of the standard
  520. .i "inherited attribute"
  521. since we use the term
  522. .i inherited
  523. in the object-oriented sense.
  524. .pp
  525. There is one problem that arises especially from the combination of ancestral attributes
  526. and inheritance. Let A, B, and C be node types and let B be a subtype of A (B \(ib A)
  527. having one ancestral attribute x. If the right-hand side of C contains an A, we have to
  528. know whether to compute the attribute A.x or not. The static type is A, but the dynamic type
  529. can be any subtype, that is A or B. If it is B we have to compute A.x, if it is A we may
  530. not compute it.
  531. The notions node type, subtype, and right-hand side are defined in section 2.
  532. .pp
  533. There are several solutions to this problem. First, one can restrict the definition of
  534. ancestral attributes to top level node types, only. This makes the reuse of existing
  535. node types very hard in particular in combination with multiple inheritance.
  536. .pp
  537. Second, one could use a dynamic dispatch technique which inspects the dynamic type of the
  538. right-hand side child and decides during runtime whether to compute A.x or not. This
  539. solution is rather inefficient because of its runtime overhead.
  540. .pp
  541. Most existing systems therefore allow single inheritance, only, with the additional
  542. restriction that ancestral attributes have to be defined at top level node types. The
  543. last restriction is not severe because it somehow coincides in a natural way with the
  544. style of usual attribute grammars.
  545. Hedin\*([<\*([[Hed89\*(]]\*(>] follows this argumentation and calls
  546. object-oriented attribute grammars having the above problem not
  547. .i "well formed" .
  548. .pp
  549. This paper introduces a third solution to the above mentioned problem. It allows for a
  550. restricted form of multiple inheritance and still retains the capability to decide at
  551. generation time which ancestral attributes have to be computed. Attribute evaluators
  552. can still be implemented efficiently as dynamic dispatch is avoided.
  553. .pp
  554. In section 2 we formally define object-oriented attribute grammars with single inheritance.
  555. Section 3 contains two simple examples using single inheritance.
  556. Section 4 extends the definition of object-oriented attribute grammars to multiple
  557. inheritance.
  558. Section 5 presents an elaborate example with multiple inheritance.
  559. In section 6 we compare our approach with pure attribute grammars and with object-oriented
  560. programming in order to reveal the common properties as well as the differences.
  561. Section 7 summarizes the results.
  562. .sh 1 "Single Inheritance"
  563. .lp
  564. This section formally defines the principles of object-oriented attribute grammars with
  565. single inheritance.
  566. As starting point we shortly recall the traditional definition of attribute grammars
  567. \*([[Knu68\*(],Knu71\*(]].
  568. .pp
  569. An attribute grammar is an extension of a context-free grammar.
  570. A context-free grammar is denoted by G = (N, T, P, Z) where
  571. N is the set of nonterminals,
  572. T is the set of terminals,
  573. P is the set of productions, and
  574. Z \(mo N is the
  575. .i start
  576. symbol, which cannot appear on the right-hand side of any production in P.
  577. The set V = N \(cu T is called the vocabulary.
  578. Each production p \(mo P has the form $ p:~X~\(->~alpha $ where X \(mo N and
  579. $ alpha~\(mo~V sup "*" $.
  580. The relation \(:> (directly derives) is defined over strings in $ V sup "*" $ as follows:
  581. if $ p:~X~\(->~alpha $, p \(mo P, $ nu X omega~\(mo~V sup "*" $,
  582. $ nu alpha omega~\(mo~V sup "*" $ then
  583. $ nu X omega~\(:>~nu alpha omega $.
  584. The relation $ \(:> sup "*" $ is the transitive and reflexive closure of \(:>.
  585. The language L(G) is defined as $ L(G)~=~"{"~w~|~Z~\(:> sup *~w~"}" $.
  586. .pp
  587. An attribute grammar augments a context-free grammar by attributes and attribute
  588. computations. A set of attributes is associated with each symbol in V.
  589. Attribute computations are added to every production describing how to compute attribute
  590. values in the local context of a production.
  591. This simple view of attribute grammars shall suffice for the scope of this paper.
  592. .pp
  593. In general there can be several productions having the same nonterminal on the left-hand side.
  594. This allows for different derivations starting from one nonterminal. In object-oriented
  595. attribute grammars, one production is permitted for one left-hand side symbol, only.
  596. This way the notions production and nonterminal (vocabulary respectively) are unified
  597. and are termed
  598. .i "node type"
  599. as already mentioned. Several different derivations are made possible through the
  600. newly introduced subtype relation.
  601. .pp
  602. An object-oriented attribute grammar is formally denoted by G = (N, T, A, C, Z) where
  603. N is the set of nonterminals,
  604. T is the set of terminals,
  605. A is the set of attributes,
  606. C is the set of attribute computations, and
  607. Z is the start symbol (Z \(mo N).
  608. The set NT = N \(cu T is called the set of
  609. .i "node types" .
  610. Each element n \(mo NT is associated with a tuple n: (R, B, D, S) where
  611. $ R~\(mo~NT sup "*" $ is the right-hand side,
  612. $ B~\(mo~A sup "*" $ is the set of attributes,
  613. $ D~\(mo~C sup "*" $ is the set of attribute computations, and
  614. S \(mo NT is the base type.
  615. .pp
  616. The elements of NT induce a relation \(ib (subtype) over NT as follows:
  617. if $ n:~( alpha ,~beta ,~delta ,~m )~\(mo~NT $ then n \(ib m.
  618. m is called
  619. .i base
  620. or
  621. .i super
  622. type, n is called
  623. .i derived
  624. type or
  625. .i subtype .
  626. The relation \(ib is transitive: if n \(ib m and m \(ib o then n \(ib o.
  627. .pp
  628. The relation \(:> (directly derives) is defined here only for the context-free or syntactic
  629. part of an object-oriented attribute grammar. There are two possibilities for derivations
  630. which are defined over strings in $ NT sup "*" $ as follows:
  631. .lp
  632. .nf
  633. .ta 3.9c
  634.       if $ nu n sub i omega~\(mo~NT sup "*" $ and    $ n sub 1 :~( alpha sub 1 ,~beta sub 1 ,~delta sub 1 ,~n sub 0 )~\(mo~NT, $
  635.     $ n sub 2 :~( alpha sub 2 ,~beta sub 2 ,~delta sub 2 ,~n sub 1 )~\(mo~NT, $
  636.                 $ ... $
  637.     $ n sub i :~( alpha sub i ,~beta sub i ,~delta sub i ,~n sub i-1 )~\(mo~NT $ then $ nu n sub i omega~\(:>~nu alpha sub 1 alpha sub 2 ... alpha sub i omega $.
  638. .lp
  639. .nf
  640.       if $ nu n omega~\(mo~NT sup "*" $ and $ m~\(ib~n $ then $ nu n omega~\(:>~nu m omega $.
  641. .lp
  642. We assume the existence of a predefined node type $ n sub 0 :~(\(o/,~\(o/,~\(o/,~-) $ with
  643. empty components. In a direct derivation step, a node type can be replaced by its right-hand
  644. side $ ( alpha sub 1 ... alpha sub i ) $ or by one of its subtypes (m). All replacing
  645. right-hand sides are the union of right-hand sides according to the subtype hierarchy.
  646. The relation $ \(:> sup "*" $ is the transitive and reflexive closure of \(:>.
  647. The language L(G) is defined as $ L(G)~=~"{"~w~|~Z~\(:> sup "*"~w~"}" $.
  648. .pp
  649. The subtype relation has the following properties: a derived node type inherits the
  650. right-hand side, the attributes, and the attribute computations from its base type. As
  651. consequence of the transitive nature of this relation, a derived type inherits all the
  652. components from all base types according to the subtype hierarchy.
  653. It may extend the set of inherited items by defining
  654. additional right-hand side elements, attributes, or attribute computations. All accumulated
  655. right-hand side elements and attributes must be distinct because they are
  656. united. An attribute computation for an attribute may overwrite an inherited one.
  657. .\" The definition of the subtype relation allows exactly single inheritance.
  658. .sh 1 Example
  659. .lp
  660. We implemented an attribute grammar system called
  661. .i ag
  662. based on object-oriented attribute grammars which is part of the Karlsruhe Toolbox for
  663. Compiler Construction\*([<\*([[GrE90\*(]]\*(>].
  664. It supports the kinds of single and multiple inheritance described in this paper.
  665. The following examples of object-oriented attribute grammars with single inheritance
  666. are written in the specification language of
  667. .i ag .
  668. The language tries to adhere to the conventional style of context-free grammars
  669. as far as possible. It offers far more features for practical usage than can be
  670. explained here. The interested reader is referred to the user's manual\*([<\*([[Gro89\*(]]\*(>].
  671. .pp
  672. An attribute grammar is given in the form of nested node type definitions. The nesting
  673. expresses the subtype hierarchy or the subtype relation. A node type definition consists of
  674. properties of the node type followed by a list of subtype definitions enclosed in angle
  675. brackets < >. The properties include the structural or syntactic definition (right-hand
  676. side), attribute definitions, and attribute computations.
  677. .(b I
  678. Example 1:
  679. .sp 0.5
  680. .FT
  681. Expr        = [Value: INTEGER]    { Value := 0; } <
  682.    Add      = Lop: Expr Rop: Expr { Value := Lop:Value + Rop:Value; } .
  683.    Sub      = Lop: Expr Rop: Expr { Value := Lop:Value - Rop:Value; } .
  684.    Const    = Integer             { Value := Integer:Value; } .
  685. > .
  686. Integer     = [Value: INTEGER] .
  687. .)b
  688. .pp
  689. The example describes the evaluation of primitive expressions. Attribute definitions are
  690. given in brackets [ ]. The attribute
  691. .i Value
  692. is associated with all subtypes of
  693. .i Expr
  694. with a default computation "Value := 0;". The attribute computations are written
  695. in curly brackets { }. The computations for the node types
  696. .i Add ,
  697. .i Sub ,
  698. and
  699. .i Const
  700. overwrite the computation given in the base type
  701. .i Expr .
  702. .pp
  703. The structural or syntactic definition is given as a sequence of node type names,
  704. possibly prefixed by a selector
  705. .i (Lop ,
  706. .i Rop )
  707. allowing unambiguous access to the component structures.
  708. .(b I
  709. Example 2:
  710. .sp 0.5
  711. .FT
  712. Stats       = <
  713.    NoStat   = .
  714.    Stat     = Next: Stats [Pos: tPosition] <
  715.       If    = Expr Then: Stats Else: Stats .
  716.       While = Expr Stats .
  717.       Call  = Actuals [Ident: tIdent] .
  718.    > .
  719. > .
  720. .)b
  721. .pp
  722. Example 2 describes a possibility for the specification of the abstract syntax of
  723. statement sequences. The example uses the node type
  724. .i Stats
  725. to describe a sequence and the node type
  726. .i Stat
  727. to describe various statements. The node types are related as subtypes showing a
  728. non-trivial subtype relation of nesting depth two. The subtype relation is:
  729. .i
  730. NoStat \(ib Stats, Stat \(ib Stats, If \(ib Stat, While \(ib Stat, Call \(ib Stat.
  731. .r
  732. In Example 2 the node types
  733. .i If ,
  734. .i While ,
  735. and
  736. .i Call
  737. inherit the child
  738. .i Next
  739. of type
  740. .i Stats
  741. and the attribute
  742. .i Pos
  743. from the base type
  744. .i Stat .
  745. They add their own children and attributes.
  746. .sh 1 "Multiple Inheritance"
  747. .lp
  748. The problem with multiple inheritance mentioned in the introduction can be solved
  749. if we distinguish two kinds of types:
  750. .i "node types"
  751. and
  752. .i "abstract types" .
  753. An abstract syntax tree is constructed only
  754. out of nodes whose type is a node type - there are no nodes whose type is an abstract one.
  755. While the node types describe production rules or tree nodes the abstract types describe
  756. concepts.
  757. .pp
  758. An object-oriented attribute grammar with multiple inheritance is formally denoted by
  759. G = (N, T, K, A, C, Z). N, T, A, C, Z represent the same entities as in the single
  760. inheritance case. In particular the set NT = N \(cu T represents the set of
  761. .i "node types" .
  762. K is the set of
  763. .i "abstract types" .
  764. Every element n \(mo NT is now associated with a quintuple
  765. n: (R, B, D, S, L) where R, B, D, and S are as before.
  766. Every element k \(mo K is associated with a quintuple k: (R, B, D, U, L)
  767. where $ U~\(mo~K $ is the base type for the single inheritance mechanism and 
  768. $ L~\(mo~K sup "*" $ is the set of base types for the multiple inheritance mechanism.
  769. We have two inheritance mechanisms which operate simultaneously. Multiple
  770. inheritance behaves similar as single inheritance: A subtype inherits all properties
  771. (right-hand side, attributes, attribute computations) from all its base types.
  772. .pp
  773. Why do we need two mechanisms for inheritance? We retained single inheritance for two
  774. reasons: First, it is good to be compatible with existing attribute grammars written in the
  775. single inheritance style. Second, the single inheritance notation allows to adhere largely
  776. to the conventional style of writing context-free grammars.
  777. .pp
  778. The above definition for object-oriented grammars with multiple inheritance distinguishes
  779. two levels (see Fig. 1).
  780. The set of abstract types represents the abstract or conceptual level. These types model
  781. concepts and properties which are common to several node types or even to different
  782. programming languages. Abstract types are not used for nodes in the syntax tree.
  783. The set of node types represents production rules of a context-free grammar. The node types
  784. describe the constructs of a programming language. Node types are used to classify the
  785. nodes in a syntax tree.
  786. .(b
  787. .PS
  788. scale    = 2.54
  789. boxwid    = 5.0
  790. boxht    = 2.0
  791. dist    = 0.3
  792.  
  793.     right
  794. B1:    box "abstract or" "conceptual" "level" invis
  795. B2:    box "abstract types" invis
  796. B3:    box "multiple" "inheritance" invis
  797.     box "production or" "node type" "level" invis at B1 + (0, -3)
  798. B5:    box "node types" invis
  799. B6:    box "single" "inheritance" invis
  800.  
  801.     arc from B2 + (0, -dist) to B2 + (0, dist) at B2 + (1, 0) ->
  802.     arc from B5 + (0, -dist) to B5 + (0, dist) at B5 + (1, 0) ->
  803.     arrow from B2 + (0, -dist) to B5 + (0, dist)
  804.     line from B3 + (-1.2, 0) to B2 + (2.2, 0)
  805.     line from B3 + (-1.2, 0) to B2 + (0.1, -2)
  806.     line from B6 + (-1.2, 0) to B5 + (2.2, 0)
  807. .PE
  808. .sp
  809. .ce
  810. Fig. 1: Inheritance among abstract types and node types
  811. .)b
  812. .pp
  813. The above definition of multiple inheritance allows multiple inheritance among abstract
  814. types and from abstract types to node types. Among node types, single inheritance is
  815. available, only. Ancestral attributes may be defined for all abstract types and
  816. for top level node types. With this restriction it is statically known for all children of
  817. all nodes whether ancestral attributes have to be computed or not.
  818. .sh 1 Example
  819. .lp
  820. In this section we present a rather elaborate example for an object-oriented attribute
  821. grammar with multiple inheritance. The example is an excerpt from a specification of the
  822. demo language MiniLAX\*([<\*([[Gro90b\*(]]\*(>]. The attribute computations are
  823. written directly in the implementation language which is Modula-2.
  824. .(z I
  825. Example 3:
  826. .sp 0.5
  827. .FT
  828. MODULE SymbolTable
  829. .sp 0.5
  830. DECLS           := [Objects: tObjects THREAD OUT] <
  831.    NODECLS      := .
  832.    DECL         := Next: Decls IN [Ident: tIdent IN] [Pos: tPosition IN]
  833.                    { Next:ObjectsIn     := mObject (ObjectsIn, Ident);
  834.                      ObjectsOut         := Next:ObjectsOut;
  835.                      CHECK NOT IsDeclared (Ident, ObjectsIn)
  836.                      ==> Error ("identifier already declared", Pos);    } .
  837. > .
  838. .sp 0.5
  839. ENV             := [Env: tEnv INH] .
  840. .sp 0.5
  841. USE   <- ENV    := [Ident: tIdent IN] [Object: tObjects SYN OUT]
  842.                    { Object             := Identify (Ident, Env);
  843.                      CHECK Object^.Kind # NoObject
  844.                      ==> Error ("identifier not declared", Pos);        } .
  845. .sp 0.5
  846. SCOPE <- ENV    := [Objects: tObjects SYN] [NewEnv: tEnv SYN]
  847.                    { Objects            := mNoObjects ();
  848.                      NewEnv             := mEnv (Objects, Env);         } .
  849. .sp 0.5
  850. END SymbolTable
  851. .)z
  852. .pp
  853. The attribute grammar module in Example 3 describes an abstract symbol table.
  854. It is termed abstract because we deal with entities called objects which are not
  855. further specified. The symbol table handles declarations of objects, applications (uses)
  856. of objects, and scopes. It does not specify what kind of objects are to be declared,
  857. where those objects are used, and which constructs are associated with scopes.
  858. We use all upper-case names to denote abstract types.
  859. .pp
  860. The first three definitions describe lists of abstract declarations. A declaration
  861. .i DECL
  862. is characterized by an identifier and a reference to a succeeding declaration.
  863. The identifier is described by two attributes
  864. .i Ident
  865. and
  866. .i Pos
  867. holding an internal representation and a source position. The right-hand side child with
  868. the selector
  869. .i Next
  870. and the node type
  871. .i Decls
  872. refers to the succeeding declaration.
  873. .pp
  874. A list of declarations
  875. .i (DECLS)
  876. is either empty
  877. .i (NODECLS)
  878. or starts with one element of type
  879. .i DECL .
  880. The list has a threaded attribute called
  881. .i Objects .
  882. This threaded attribute actually stands for two attributes called
  883. .i ObjectsIn
  884. and
  885. .i ObjectsOut .
  886. The attribute computations given for
  887. .i DECL
  888. in curly brackets { } use this threaded attributes(s) to collect all declared objects in a
  889. list. They make use of functions from an external data type.
  890. .i mNoObjects
  891. creates an empty list,
  892. .i mObject
  893. adds a description of an object to a list, and
  894. .i IsDeclared
  895. checks for multiple declarations. The latter function is used in a condition (CHECK) that
  896. issues an error message in case of multiple declarations.
  897. .pp
  898. The abstract type
  899. .i SCOPE
  900. describes scopes such as blocks or procedures. The attribute
  901. .i Env
  902. (for environment) which is inherited from the abstract type
  903. .i ENV
  904. describes the set of
  905. objects that is visible at certain locations in a program. Multiple inheritance is
  906. expressed by writing an arrow <- and a list of abstract (base) types behind a type.
  907. A scope is supposed to reside in a surrounding environment described by the attribute
  908. .i Env
  909. and to introduce a new set of declarations represented by the attribute
  910. .i Objects .
  911. It computes a new environment attribute
  912. .i NewEnv
  913. valid inside this scope by calling the external function
  914. .i mEnv .
  915. The computation of the attribute
  916. .i Objects
  917. is a dummy to satisfy the completeness requirement of attribute grammars.
  918. .pp
  919. The abstract type
  920. .i USE
  921. describes the application or use of objects. A construct that uses an object has an
  922. attribute giving the identifier of the object
  923. .i (Ident) .
  924. This construct possesses an environment attribute
  925. .i Env
  926. that describes all objects visible at this construct. The attribute
  927. .i Object
  928. is used to refer to the symbol table entry of the used object. The external function
  929. .i Identify
  930. takes the attributes
  931. .i Ident
  932. and
  933. .i Env
  934. as arguments and computes the attribute
  935. .i Object .
  936. In case of the use of an undeclared identifier the CHECK statement will issue an
  937. appropriate error message.
  938. .pp
  939. The attribute definitions in Example 3 use a few keywords. These associate so-called
  940. properties with the attributes.
  941. IN characterizes input attributes that have already a value when attribute evaluation
  942. starts. The value is usually supplied during tree construction.
  943. OUT characterizes output attributes whose value is needed after attribute evaluation.
  944. Those attributes may not be removed from the tree nodes by an optimizer.
  945. SYN and INH classify the attributes as
  946. .i synthesized
  947. and
  948. .i ancestral .
  949. .pp
  950. Example 4 shows the connection of the abstract symbol table with the abstract syntax of the
  951. language MiniLAX. The subset of the node type definitions relevant for the symbol table
  952. problem is given. Whereas abstract types are introduced with the symbol := the character =
  953. is used for node types.
  954. .(z I
  955. Example 4:
  956. .sp 0.5
  957. .FT
  958. MODULE AbstractSyntax
  959. .sp 0.5
  960. MiniLax            = Proc .
  961. Decls <- DECLS     = <
  962.    NoDecl          = .
  963.    Decl <- DECL    = <
  964.       Var          = Type .
  965.       Proc         = Formals Decls Stats .
  966.    > .
  967. > .
  968. Stats              = <
  969.    NoStat          = .
  970.    Stat            = Next: Stats <
  971.       Assign       = Adr Expr            [Pos: tPosition] .
  972.       Call <- USE  = Actuals             [Pos: tPosition] .
  973.       If           = Expr Then: Stats Else: Stats .
  974.       While        = Expr Stats .
  975.       Read         = Adr .
  976.       Write        = Expr .
  977.    > .
  978. > .
  979. Expr               =                     [Pos: tPosition] <
  980.    Binary          = Lop: Expr Rop: Expr [Operator: SHORTCARD] .
  981.    Unary           = Expr                [Operator: SHORTCARD] .
  982.    IntConst        =                     [Value: INTEGER] .
  983.    RealConst       =                     [Value: REAL   ] .
  984.    BoolConst       =                     [Value: BOOLEAN] .
  985.    Adr             = <
  986.       Index        = Adr Expr .
  987.       Ident <- USE = .
  988.    > .
  989. > .
  990. .sp 0.5
  991. END AbstractSyntax
  992. .)z
  993. .pp
  994. A concrete list of declarations is described by the node type
  995. .i Decls
  996. which is a subtype of the abstract type
  997. .i DECLS .
  998. A single declaration is described by the node type
  999. .i Decl
  1000. which inherits from
  1001. .i DECL .
  1002. Two specializations are derived from the node type
  1003. .i Decl
  1004. describing two kinds of declarations: variables and procedures
  1005. .i (Var
  1006. and
  1007. .i Proc) .
  1008. Through inheritance from
  1009. .i DECL
  1010. every
  1011. .i Decl
  1012. specifies already an identifier (attributes
  1013. .i Ident
  1014. and
  1015. .i Pos )
  1016. and a reference to a succeeding declaration (attribute
  1017. .i Next ).
  1018. Therefore the specializations have just to add the missing components which is a
  1019. description of the type in case of a variable and the formal parameters, the local
  1020. declarations, and the procedure body
  1021. .i (Formals ,
  1022. .i Decls ,
  1023. .i Stats )
  1024. in case of a procedure.
  1025. .pp
  1026. The language knows two locations where objects are used: at a procedure call and at a
  1027. variable occurring in an expression. Therefore the node types
  1028. .i Call
  1029. and
  1030. .i Ident
  1031. are subtypes of the abstract type
  1032. .i USE .
  1033. The node type
  1034. .i Call
  1035. specializes the usage of an object by adding a list of actual parameters and an attribute
  1036. .i Pos
  1037. which is needed for an error message.
  1038. .pp
  1039. The attribute computations in the attribute grammar for MiniLAX are grouped into modules
  1040. (see Example 5). We present excerpts from three modules that are involved in the
  1041. symbol table problem. The part of the module
  1042. .i Decls
  1043. shown in Example 5 specializes the computation of the attribute
  1044. .i Next:ObjectsIn
  1045. for the concrete declarations of the language. This way the information in the symbol table
  1046. is extended by the kind of the declared object, the type of variables, and the formal
  1047. parameters of procedures.
  1048. .(z I
  1049. Example 5:
  1050. .sp 0.5
  1051. .FT
  1052. MODULE Decls
  1053. .sp 0.5
  1054. Proc           = { Next:ObjectsIn := mProc (ObjectsIn, Ident, Formals); } .
  1055. Var            = { Next:ObjectsIn := mVar  (ObjectsIn, Ident, Type);    } .
  1056. .sp 0.5
  1057. END Decls
  1058. .sp 0.5
  1059. MODULE Env
  1060. .sp 0.5
  1061. Decls   <- ENV = .
  1062. Stats   <- ENV = .
  1063. Actuals <- ENV = .
  1064. Expr    <- ENV = .
  1065. .sp 0.5
  1066. MiniLax        = { Proc:Env  := NoEnv           ; } .
  1067. DECL          := { Next:Env  := NoEnv           ; } .
  1068. Decl           = { Next:Env  := Env             ; } .
  1069. Proc <- SCOPE  = { Objects   := Decls:ObjectsOut;
  1070.                    Stats:Env := NewEnv          ;
  1071.                    Decls:Env := NewEnv          ; } .
  1072. .sp 0.5
  1073. END Env
  1074. .sp 0.5
  1075. MODULE Conditions
  1076. .sp 0.5
  1077. Call           = { CHECK IsObjectKind (Object, Proc)
  1078.                    ==> Error ("only procedures can be called", Pos); } .
  1079. Ident          = { CHECK IsObjectKind (Object, Var)
  1080.                    ==> Error ("variable required"            , Pos); } .
  1081. .sp 0.5
  1082. END Conditions
  1083. .)z
  1084. .pp
  1085. The module named
  1086. .i Env
  1087. specifies all computations for the environment attribute.
  1088. It is reproduced completely. All node types
  1089. whose subtrees can contain applications of objects need an environment attribute
  1090. .i Env
  1091. and become therefore subtypes of the abstract type
  1092. .i ENV :
  1093. .i Decls ,
  1094. .i Stats ,
  1095. .i Actuals ,
  1096. and
  1097. .i Expr .
  1098. The first attribute computation of
  1099. .i Proc
  1100. connects the "interfaces" of the abstract types
  1101. .i DECLS
  1102. and
  1103. .i SCOPES .
  1104. The attribute
  1105. .i Decls:ObjectsOut
  1106. is the collected list of locally declared objects. It is assigned to the attribute
  1107. .i Objects
  1108. which is required to hold this information from the point of view of the abstract type
  1109. .i SCOPE .
  1110. .i SCOPE
  1111. computes an attribute
  1112. .i NewEnv
  1113. describing the objects visible inside the procedure. The value of this attribute is passed
  1114. to the attributes
  1115. .i Stats:Env
  1116. and
  1117. .i Decls:Env
  1118. to make the environment available for the components of the procedure.
  1119. The rules given in the module
  1120. .i Env
  1121. suffice to specify all computations necessary for the environment attribute. The many
  1122. missing rules are inserted automatically by the tool
  1123. .i ag
  1124. as simple copy rules.
  1125. .pp
  1126. Finally, the module
  1127. .i Conditions
  1128. adds checks to the locations where objects are used. The abstract type
  1129. .i USE
  1130. already checks whether an object is declared or not. We still need to check if an object is
  1131. of the right kind. This test is performed by the external procedure
  1132. .i IsObjectKind .
  1133. .sh 1 Comparison
  1134. .pp
  1135. This section compares object-oriented attribute grammars as introduced in this paper with the
  1136. well-known concepts of (attribute) grammars, tree and record types, type extensions, and
  1137. object-oriented programming.
  1138. The goal is to reveal the common properties as well as the differences among these
  1139. concepts. These areas are related because of the following reasons:
  1140. attribute grammars are usually based on context-free grammars. An attribute grammar
  1141. specifies an evaluation of attributes of a tree defined by such a context-free grammar.
  1142. Trees can be implemented using a set of record type declarations. Therefore
  1143. context-free grammars, trees, and record types deal more or less with the
  1144. same concept. Table 1 compares the most important notions from
  1145. these areas. Additionally we included the notions from the area of
  1146. object-oriented (oo) programming as described e. g. in
  1147. \*([[Bla89\*(]].
  1148. .(b L
  1149. .sp 0.5
  1150. .TS
  1151. center box;
  1152. l | l | l | l.
  1153. (attribute) grammars    trees    types    oo-programming
  1154. _
  1155. rule        node type    record type    class
  1156. attribute    field in a node type    record field    instance variable
  1157. nonterminal    set of node types    union of record types    -
  1158. terminal    distinct node type    record type without    -
  1159.            pointer fields
  1160. rule application    tree node    record variable    object, instance
  1161. attribute computation    -    procedure declaration    method
  1162. -    -    procedure call    message
  1163. -    -    base type    superclass
  1164. -    -    derived type    subclass
  1165. -    -    extension    inheritance
  1166. .TE
  1167. .sp 0.5
  1168. .ce
  1169. Table 1: Comparison of notions from the areas of grammars, trees, types, and oo-programming
  1170. .)b
  1171. .pp
  1172. Object-oriented attribute grammars are missing in Table 1. For them we used the notions from
  1173. attribute grammars and added the notions
  1174. node type, base type, subtype or derived type, and inheritance from the other areas.
  1175. .sh 2 "Attribute Grammars"
  1176. .pp
  1177. Conventional grammars in BNF allow several productions with the same nonterminal symbol on the
  1178. left-hand side. A node type in object-oriented attribute grammars, which corresponds to a
  1179. nonterminal as well as to a rule name, has exactly one right-hand side.
  1180. The selector names can be regarded as syntactic sugar.
  1181. To allow for several different derivations, a subtype relation between node types is added.
  1182. During a derivation, a node type may be replaced
  1183. by its right-hand side or by a subtype.
  1184. .\" Additionally, the subtype feature allows to express chain rules and single inheritance.
  1185. Inheritance is a notation to factor out parts that are common to several node types such
  1186. as right-hand sides, attributes, and attribute computations.  Fortunately, attributes
  1187. local to a rule (node type) are possible without any special construct.
  1188. .pp
  1189. Object-oriented attribute grammars are a notation to write BNF grammars in a short and
  1190. concise way and where the underlying tree structure can be exactly described. With respect
  1191. to attribute grammars the same notational advantages hold.
  1192. Attribute grammars are a special case of object-oriented attribute grammars. They are
  1193. characterized by a one level subtype hierarchy, right-hand sides and attribute computations
  1194. are defined for subtypes only, and attributes are associated only with base types.
  1195. In terms of attribute grammar classes
  1196. or attribute grammar semantics object-oriented attribute grammars are equivalent to
  1197. attribute grammars.
  1198. .sh 2 "Trees and Records"
  1199. .pp
  1200. When trees are stored in memory, they can be represented by linked records. Every node type
  1201. corresponds to a record type. Object-oriented attribute grammars directly describe the
  1202. structure of attributed syntax trees. The node types can be seen as record types. The
  1203. right-hand side elements resemble pointer valued fields describing the tree structure and the
  1204. attributes are additional fields for arbitrary information stored at tree nodes. The field
  1205. name and field type needed for record types are also present in the node types of
  1206. object-oriented attribute grammars.
  1207. .sh 2 "Type Extensions"
  1208. .pp
  1209. Type extensions have been introduced with the language
  1210. Oberon by Wirth\*([<\*([[Wir88a\*(],Wir88b\*(],Wir88c\*(]]\*(>].
  1211. They allow the definition of a record type based on an existing record type by adding record
  1212. fields. This extension mechanism induces a subtype relation between record types. The 
  1213. subtype and inheritance features are equivalent in object-oriented attribute grammars and type
  1214. extensions with the difference that Wirth uses the word extension in place of inheritance
  1215. and restricts it to single inheritance.
  1216. .sh 2 "Object-Oriented Programming"
  1217. .pp
  1218. The concepts of subtype and inheritance in object-oriented attribute grammars and
  1219. object-oriented programming have many similarities
  1220. and this explains the name object-oriented attribute grammars.
  1221. The notions class, instance variable,
  1222. object, superclass, and subclass have direct counter parts (see Table 1).
  1223. There are also some differences.  Object-oriented programming allows an
  1224. arbitrary number of named methods which are activated by explicitly sending
  1225. messages. In object-oriented attribute grammars there is exactly one
  1226. attribute computation for an attribute. This computation corresponds to an unnamed method.
  1227. There is nothing like messages: The attribute computation for an attribute is activated
  1228. implicitly and exactly once.
  1229. .sh 1 Summary
  1230. .lp
  1231. We presented object-oriented attribute grammars with single and multiple inheritance. The
  1232. distinction between abstract types and node types allows for a restricted form of multiple
  1233. inheritance that can still be implemented efficiently. The nonterminals or node types are
  1234. the entities constituting the inheritance hierarchy. The items that are subject to
  1235. inheritance are right-hand side elements, attributes, and attribute computations.
  1236. .pp
  1237. Object-oriented attribute grammars are a compact and flexible notation for language
  1238. specifications. The repetition of information is avoided as common parts can be factored
  1239. out. The reuse of definitions is supported - new definitions can be derived from existing
  1240. ones by specializations.
  1241. .pp
  1242. We extended the attribute evaluator generator
  1243. .i ag
  1244. to process object-oriented attribute grammars with multiple inheritance. It turned out that
  1245. it is possible to generate efficient attribute evaluators for this kind of attribute
  1246. grammars.
  1247. .pp
  1248. While we are very satisfied with the advantages of single inheritance we have
  1249. just started to explore the feasibility of multiple inheritance. Our current goal is to
  1250. build a collection of attribute grammar modules containing abstract types that model
  1251. concepts of programming languages such as the discussed symbol table. Together with
  1252. abstract data types these will result a library of reusable parts oriented towards
  1253. semantic analysis of programming languages. If possible those parts will be designed to
  1254. specify aspects of semantic analysis independent of concrete languages.
  1255. .fi
  1256. .sz 12
  1257. .[]
  1258. .[-
  1259. .ds [F Bla89
  1260. .ds [A G\*(p] Blaschek
  1261. .ds [T Implementation of Objects in Modula-2
  1262. .nr [P 1
  1263. .ds [P 147-155
  1264. .ds [J Structured Programming
  1265. .ds [V 10
  1266. .ds [N 3
  1267. .ds [D 1989
  1268. .][
  1269. .[-
  1270. .ds [F Gro89
  1271. .ds [A J\*(p] Grosch
  1272. .ds [T Ag - An Attribute Evaluator Generator
  1273. .ds [I GMD Forschungsstelle an der Universit\\*:at Karlsruhe
  1274. .ds [R Compiler Generation Report No. 16
  1275. .ds [N 16
  1276. .ds [D Aug. 1989
  1277. .][
  1278. .[-
  1279. .ds [F Gro90a
  1280. .ds [A J\*(p] Grosch
  1281. .ds [T Object-Oriented Attribute Grammars
  1282. .ds [E A\*(p]\*(a]E\*(p] Harmanci
  1283. .as [E \*(n]E\*(p] Gelenbe
  1284. .nr [E 2
  1285. .ds [B Proceedings of the Fifth International Symposium on Computer and Information Sciences (ISCIS V)
  1286. .ds [C Cappadocia, Nevsehir, Turkey
  1287. .nr [P 1
  1288. .ds [P 807-816
  1289. .ds [D Oct. 1990
  1290. .][
  1291. .[-
  1292. .ds [F Gro90b
  1293. .ds [A J\*(p] Grosch
  1294. .ds [T Specification of a Minilax Interpreter
  1295. .ds [I GMD Forschungsstelle an der Universit\\*:at Karlsruhe
  1296. .ds [R Compiler Generation Report No. 22
  1297. .ds [N 22
  1298. .ds [D Mar. 1990
  1299. .][
  1300. .[-
  1301. .ds [F GrE90
  1302. .ds [A J\*(p] Grosch
  1303. .as [A \*(n]H\*(p] Emmelmann
  1304. .ds [T A Tool Box for Compiler Construction
  1305. .ds [V 477
  1306. .ds [J LNCS
  1307. .ds [C Berlin
  1308. .ds [I Springer Verlag
  1309. .nr [P 1
  1310. .ds [P 106-116
  1311. .ds [D Oct. 1990
  1312. .][
  1313. .[-
  1314. .ds [F Hed89
  1315. .ds [A G\*(p] Hedin
  1316. .ds [T An Object-Oriented Notation for Attribute Grammars
  1317. .ds [J Proc. of the European Conference on Object-Oriented Programming (ECOOP '89)
  1318. .ds [I The British Computer Society Workshop Series, Cambridge, University Press
  1319. .ds [C Nottingham
  1320. .nr [P 1
  1321. .ds [P 329-345
  1322. .ds [D 1989
  1323. .][
  1324. .[-
  1325. .ds [F Knu68
  1326. .ds [A D\*(p]\*(a]E\*(p] Knuth
  1327. .ds [T Semantics of Context-Free Languages
  1328. .nr [P 1
  1329. .ds [P 127-146
  1330. .ds [J Mathematical Systems Theory
  1331. .ds [V 2
  1332. .ds [D June 1968
  1333. .ds [N 2
  1334. .][
  1335. .[-
  1336. .ds [F Knu71
  1337. .ds [A D\*(p]\*(a]E\*(p] Knuth
  1338. .ds [T Semantics of Context-free Languages: Correction
  1339. .nr [P 1
  1340. .ds [P 95-96
  1341. .ds [J Mathematical Systems Theory
  1342. .ds [V 5
  1343. .ds [D Mar. 1971
  1344. .][
  1345. .[-
  1346. .ds [F Kos91
  1347. .ds [A K\*(p] Koskimies
  1348. .ds [T Object-Orientation in Attribute Grammars
  1349. .ds [V 545
  1350. .ds [J LNCS
  1351. .ds [C Berlin
  1352. .ds [I Springer Verlag
  1353. .nr [P 1
  1354. .ds [P 297-329
  1355. .ds [D 1991
  1356. .][
  1357. .[-
  1358. .ds [F Wir88a
  1359. .ds [A N\*(p] Wirth
  1360. .ds [T Type Extensions
  1361. .ds [J ACM Trans. Prog. Lang. and Systems
  1362. .ds [V 10
  1363. .ds [N 2
  1364. .ds [D Apr. 1988
  1365. .nr [P 1
  1366. .ds [P 204-214
  1367. .][
  1368. .[-
  1369. .ds [F Wir88b
  1370. .ds [A N\*(p] Wirth
  1371. .ds [T From Modula to Oberon
  1372. .ds [J Software\(emPractice & Experience
  1373. .ds [V 18
  1374. .ds [N 7
  1375. .ds [D July 1988
  1376. .nr [P 1
  1377. .ds [P 661-670
  1378. .][
  1379. .[-
  1380. .ds [F Wir88c
  1381. .ds [A N\*(p] Wirth
  1382. .ds [T The Programming Language Oberon
  1383. .ds [J Software\(emPractice & Experience
  1384. .ds [V 18
  1385. .ds [N 7
  1386. .ds [D July 1988
  1387. .nr [P 1
  1388. .ds [P 671-690
  1389. .][
  1390. .bp 1
  1391. .lp
  1392. .b Contents
  1393. .sp
  1394. .xp
  1395.